#include "main.h";

class PaintRobot {
        private:
                TImage *img;
                int rozmer_mriezky;
                int rozmer_bunky;
        public:
                PaintRobot();
                PaintRobot(TImage *p_img, int b_rozmer, int p_rozmer);
                void VycistiPlochu();
                void Mriezka();
                void Kamen(TColor clr, int x, int y);
                bool isImage();
                int DrawPlayground(typPole& playground, TColor clrWhite, TColor clrBlack);
                void helpMoves(Coordinates *coords);
};

PaintRobot::PaintRobot() {
        img = NULL;
        rozmer_mriezky = 0;
        rozmer_bunky = 0;
}

PaintRobot::PaintRobot(TImage *p_img, int b_rozmer, int p_rozmer) {
        img = p_img;
        rozmer_mriezky = p_rozmer;
        rozmer_bunky = b_rozmer;
}

bool PaintRobot::isImage() {
        if (img) {
                return true;
        }
        else {
                return false;
        }
}

void PaintRobot::Mriezka() {

        //nakresli zvysle ciary pre mriezku
        for (int i = 0; i < rozmer_mriezky; i++) {
                //presun sa na poziciu odkial sa bude kreslit
                img->Canvas->MoveTo(i*rozmer_bunky, 0);
                img->Canvas->LineTo(i*rozmer_bunky, img->Height);
        }

        //nakresli vodorovne ciary pre mriezku
        for (int i = 0; i < rozmer_mriezky; i++) {
                //presun sa na poziciu odkial sa bude kreslit
                img->Canvas->MoveTo(0, i*rozmer_bunky);
                img->Canvas->LineTo(img->Width, i*rozmer_bunky);
        }

}

void PaintRobot::Kamen(TColor clr, int x, int y) {
        img->Canvas->MoveTo(x*rozmer_bunky+5, y*rozmer_bunky+5);
        img->Canvas->Brush->Color = clr;
        img->Canvas->Ellipse(x*rozmer_bunky+5, y*rozmer_bunky+5, x*rozmer_bunky+45, y*rozmer_bunky+45);
}

int PaintRobot::DrawPlayground(typPole& playground, TColor clrWhite, TColor clrBlack) {
        VycistiPlochu();
        Mriezka();
        for (int i = 0; i < rozmer_mriezky; i++) {
                for (int j = 0; j < rozmer_mriezky; j++) {
                        if (playground[i][j] == 1) {
                                this->Kamen(clrWhite, j, i);
                        }
                        if (playground[i][j] == 2) {
                                this->Kamen(clrBlack, j, i);
                        }
                }
        }

        return 1;
}

void PaintRobot::VycistiPlochu() {
        img->Canvas->Brush->Color = clWhite;
        img->Canvas->Rectangle(0, 0, img->Width, img->Height);
}

void PaintRobot::helpMoves(Coordinates *coords) {
        int x,y;
        img->Canvas->Brush->Color = clLtGray; //nastav farbu pre vyfarbenie policka
        while (coords != NULL) {
                x = coords->getY()*rozmer_bunky; //x-ova suradnica zaciatku policka (lavy horny roh)
                y = coords->getX()*rozmer_bunky; //y-ova suradnica zaciatku policka (lavy horny roh)
                //vyfarbi policko na suradniciach
                //[x,y] - lavy horny
                //[x+rozmer_mriezky,y+rozmer_mriezky] - pravy dolny
                img->Canvas->Rectangle(x, y, x+rozmer_bunky+1, y+rozmer_bunky+1);
                coords = coords->getNext();
        }
}






